<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel" align="center">
                    自动化装配反馈状态维护
                </h4>
            </div>
            <div class="modal-body">
                <form id="partForm" class="form-horizontal" role="form">
                    <input type="hidden" id="id" name="id">
                    <div class="form-group">
                        <label class="col-md-3 control-label">开始时间 :</label>
                        <div class="col-md-9">
                            <input id="eleStartDate" type="text" class="form-control datepicker" name="eleStartDate"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">状态 ：</label>
                        <div class="col-sm-9">
                            <select id="eleStatus" class="form-control" name="eleStatus">
                                <option value="1" selected>未开始</option>
                                <option value="2">执行中</option>
                                <option value="3">已完成</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">结束时间 :</label>
                        <div class="col-md-9">
                            <input id="eleEndDate" type="text" class="form-control datepicker" name="eleEndDate"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">备注 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="eleBackRemark" id="eleBackRemark">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="saveMaintain()" id="btn-add">
                    提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<section class="content-header">
    <h1>自动化装配任务反馈</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-prodNo">生产令号</label>
                                    <input id="query-prodNo" type="text" name="prodNo" class="form-control"
                                           placeholder="请输入生产令号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-part">部分</label>
                                    <input id="query-part" type="text" name="part" class="form-control"
                                           placeholder="请输入部分">
                                </div>
                                <div class="form-group">
                                    <label for="query-drawNo">图号</label>
                                    <input id="query-drawNo" type="text" name="drawNo" class="form-control"
                                           placeholder="请输入图号">
                                </div>
                                <div class="form-group">
                                    <label for="query-drawName">图名</label>
                                    <input id="query-drawName" type="text" name="drawName" class="form-control"
                                           placeholder="请输入图名">
                                </div>
                                <div class="form-group">
                                    <label for="query-status">反馈状态</label>
                                    <select id="query-status" class="form-control selectpicker" name="eleStatus" multiple>
                                        <option value="1" selected>未完成</option>
                                        <option value="2" selected>执行中</option>
                                        <option value="3">已完成</option>
                                    </select>
                                    <input name="eleStatusText" type="hidden" value="1,2" style="display: none"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;

    $(function () {

        /** 多选状态 */
        $("#queryForm [name='eleStatus']").change(function () {
            $("#queryForm [name='eleStatusText']").val($("#queryForm [name='eleStatus']").val());
        })

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "assemble/dispatch/backPageList",
            showExport: false,
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "生产令号", field: 'prodNo'},
                {
                    title: "订单数量", field: 'proNum',
                    formatter: function (value, row) {
                        return row.proNum + row.proUnit;
                    }
                },
                {title: "项目名称", field: 'proName'},
                {title: "部分", field: 'part'},
                {title: "装配图号", field: 'drawNo'},
                {title: "装配名称", field: 'drawName'},
                {title: "装配数量", field: 'drawNum'},
                {
                    title: "状态", field: 'eleStatus',
                    formatter: function (value, row) {
                        if (value === 1) {
                            return '<span class="badge label-inverse">未完成</span>';
                        } else if (value === 2) {
                            return '<span class="badge label-warning">执行中</span>';
                        } else if (value === 3) {
                            return '<span class="badge label-success">已完成</span>';
                        }
                    }
                },
                {title: "开始时间", field: 'eleStartDate'},
                {title: "结束时间", field: 'eleEndDate'},
                {title: "备注", field: 'eleBackRemark'},
                {
                    title: "操作", width: '100',
                    formatter: function (value, row) {
                        let actions = [];
                        actions.push('<a class="btn btn-info btn-xs" target="_blank" href="' + ctx + 'assemble/assMake/makeView/' + row.id + '" > 查看</a>');
                        if (hasP('asseOrd:eleBack:edit')) {
                            actions.push('<a class="btn btn-warning btn-xs"   href="javascript:void(0)"  onclick="edit(' + js.jsonStringify(row) + ')"> 编辑</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });

    });

    /**编辑状态按钮*/
    function edit(row) {
        $("#partForm").fillSpan(row);
        $("#partForm").fillData(row);
        js.modal.open("myModal");
    }

    /**保存模态框*/
    function saveMaintain() {
        let status = $("#eleStatus").val();

        if (status == 2) {
            let res = js.vd({
                id: 'partForm',
                notEmpty: ['eleStartDate']
            })
            if (!res) {
                return;
            }
        }
        if (status == 3) {
            let res = js.vd({
                id: 'partForm',
                notEmpty: ['eleStartDate', 'eleEndDate']
            })
            if (!res) {
                return;
            }
            if ($("#eleStartDate").val() > $("#eleEndDate").val()) {
                alert("结束时间必须在开始时间之后！！");
                return;
            }
        }
        var url = ctx + "assemble/dispatch/eleBakeSave";
        js.validSubmit({
            formId: "partForm",
            url: url,
            data: new FormData($("#partForm")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("myModal");
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });

    }

</script>
</body>
</html>
